﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using FM.Common;
using FM.Services;
using FM.录音.Models;
using FM.录音.Services;
using FM.录音.接口;
using FM.接口;
using Microsoft.Practices.Prism.Logging;
using Microsoft.Practices.Prism.PubSubEvents;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Unity;
using NLog.Fluent;

namespace FM.录音.ViewModels
{
    public class 录音视图组ViewModel : Vm基类<录音视图组Model>, I子视图
    {
        private IUnityContainer 人事部;
        private IEventAggregator 新闻部;
        private ILoggerFacade log;
        private string _时间;
        I定时器 timer ;

        public string 时间
        {
            get { return _时间; }
            set { SetProperty(ref _时间 , value) ; }
        }

        public 录音视图组ViewModel(IUnityContainer 人事部cs, IEventAggregator 新闻部cs)
        {
            人事部 = 人事部cs;
            新闻部 = 新闻部cs;

            启动时间服务();

            log = 人事部.Resolve<ILoggerFacade>();
            Model = new 录音视图组Model();
            子视图列表 = new ObservableCollection<ContentControl>();
            加载模块();

        }

        private void 启动时间服务()
        {
            timer= new 定时器1();
            timer.事件 += (o,e) => 时间 = DateTime.Now.ToString("yyyy年MM月dd日 dddd HH:mm:ss");
            timer.Is启动 = true;
        }

        

        public ObservableCollection<ContentControl> 子视图列表 { get; set; }

        private void 加载模块()
        {
            var 配置1 = 运行状态.系统配置1;
            Model.录音配置 = 配置1.录音配置;


            for (int i = 0; i < Model.录音配置.Length; i++)
            {
                var k = i;

                var 视图2 = 人事部.Resolve<Views.录音视图>();
                var model2 = 人事部.Resolve<ViewModels.录音视图ViewModel>();
                model2.ID = k+1;
                model2.录音配置 = Model.录音配置[k];

                视图2.DataContext = model2;
                子视图列表.Add(视图2);
            }
        }
    }
}